﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CRMSalesManagement.FrontPageShow
{
    public partial class ProductShow : System.Web.UI.Page
    {
        private static string newsType = "";
        private static string productBrand = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["type"] != null)
                {
                    newsType = Request.QueryString["type"].ToString();                   
                }
                if (Request.QueryString["brand"] != null)
                {
                    productBrand = Request.QueryString["brand"].ToString();
                }
                int pageNum = 1;
                if (Request.QueryString["page"] != null)
                {
                    pageNum = int.Parse(Request.QueryString["page"]);
                }
                int total = 0;
                IList<CRM.DataLayer.Product> dataResult =null;
                //按产品类型查询
                if (productBrand== "Y"&&newsType!="Y")
                {
                    if (newsType == "产品展示")
                    {
                        dataResult = CRM.Business.Product.ProductsShow(out total, pageNum, this.DataPage1.ShowRecordCount);
                    }
                    else
                    {
                        dataResult = CRM.Business.Product.ProductsShow(out total, pageNum, this.DataPage1.ShowRecordCount, newsType);
                    }
                }
                else
                {
                    //按品牌查询
                    dataResult = CRM.Business.Product.ProductsShowByBrand(out total, pageNum, this.DataPage1.ShowRecordCount, productBrand); 
                }
               // var messageDb = CRM.Business.Messages.PagePublishedListVisitorMessage(out total, pageNum, this.DataPage1.ShowRecordCount);
                this.DataPage1.TotalRecordCount = total;
                this.DataPage1.ShowPageNumberCount = pageNum;
                if (dataResult != null)
                {
                    this.dlResult.DataSource = dataResult;
                    this.DataBind();
                    if (this.DataPage1.TotalRecordCount == 0)
                    {
                        lblProduct.Text = "*暂无信息";
                        lblProduct.Visible = true;
                    }
                    else
                    {
                        lblProduct.Visible = false;
                    }
                }

                #region 控制分页控件
                CRM.Business.ShowPageDispaly.PageDispaly(this.DataPage1, pageNum, total);
                #endregion               
            }
        }
    }
}